package com.xinziruo.crawl.infrastruture.support.command;

import static com.xinziruo.crawl.infrastruture.support.command.CommandConstant.*;

/**
 * 
 * @author loudyn
 * 
 */
public abstract class AbstractCommand implements Command {
	private byte[] content;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.youboy.client.command.Command#length()
	 */
	public final int length() {
		return CONTENT_TYPE_BYTES + content().length;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.youboy.client.command.Command#content()
	 */
	public final byte[] content() {
		
		if (null == this.content) {
			return new byte[] {};
		}
		
		return this.content;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.youboy.client.command.Command#content(byte[])
	 */
	public final Command content(byte[] content) {
		this.content = content;
		return this;
	}

}
